#ifndef PACK_H
#define PACK_H

#include <QTcpSocket>
#include <QObject>
#include <vector>
#include <string>
#include <QString>
#include <QStringList>

enum Type {
    TYPE_REGIST,
    TYPE_LOGIN,
    TYPE_FILE_UPLOAD_REQUEST,
    TYPE_FILE_UPLOADING,
    TYPE_FILE_UPLOAD_END,
    TYPE_SENDING_CAMERA,
    TYPE_SEND_CAMERA_END,
    TYPE_SENDING_DESKTOP,
    TYPE_SEND_DESKTOP_END,
    TYPE_SCHEDULE_SAVE,
    TYPE_SCHEDULE_UPDATE,
    TYPE_SCHEDULE_DELETE,
    TYPE_SCHEDULE_QUERY,
    TYPE_SCHEDULE_QUERY_ALL,
    TYPE_USER_ONLINE,
    TYPE_USER_OFFLINE,
    TYPE_ONLINE_LIST,
    TYPE_MESSAGE,
    TYPE_MESSAGE_ACK,
    TYPE_TEXT,
    TYPE_SENDING_AUDIO,
    TYPE_SEND_AUDIO_END
};

// 协议包发给服务器之后，服务器要处理，如果处理成功，服务器发给客户端的协议包里面的Back，就是SUCCESS
enum Back{
    BACK_SUCCESS,
    BACK_ERR
};

class Pack
{
private:
    int pack_size = 12;// 记录整个协议包大小，方便服务器知道当前发过去的协议包有多大
    Type type;
    Back back;
    char buf[4096] = "";
    int used = 0;
    QString list;
public:
    Pack();
    void append(const QString& val);// 将外部的字符串数据，写入协议包的buf里面
    void append(const char* p,int size);
    QStringList readAll()const;// 读取协议包的buf所有字符串
    QByteArray readAll(int size);
    Pack& operator<<(const QString& val);
    void operator>>(QTcpSocket* client);

    void setType(Type type);
    void setBack(Back back);
    void setSize(int size);

    int size(); // pack_size的get接口
    Type getType()const;
    Back getBack()const;
};

#endif // PACK_H
